<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>添加（编辑）广告位置</title>
<link href="__PUBLIC__/admin/css/xc.min.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/admin/css/xc.admin.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.js"></script> 
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.admin.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/common-1.0.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/WdatePicker.js"></script>
</head>

<body>
<div class="pd-10">
  <form action="" method="post" class="form form-horizontal" id="myform" enctype="multipart/form-data">
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>广告名称：</label>
      <div class="formControls col-8">
        <input type="text" class="input-text" placeholder="请输入广告名称" id="aname" name="aname" value="{$res.ad_name}">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3">广告位置：</label>
      <div class="formControls col-8"> <span class="select-box">
        <select class="select" size="1" id="type" name="type">
          <volist name='type' id='vo'>
           <option value="{$vo.po_id}" <if condition='($res[ad_pid] eq $vo[po_id])'>selected</if>>{$vo.po_name}&nbsp;{$vo.po_width}*{$vo.po_height}</option>
          </volist>
        </select></span>
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>开始日期：</label>
      <div class="formControls col-8">
        <input type="text" class="input-text Wdate" id="stime" name="stime" onfocus="WdatePicker()" value="{$res.ad_stime|default=time()|date='Y-m-d',###}">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>结束日期：</label>
      <div class="formControls col-8">
        <input type="text" class="input-text Wdate" id="etime" name="etime" onfocus="WdatePicker()" value="{$res.ad_etime|default=strtotime('+1year',time())|date='Y-m-d',###}">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>广告链接：</label>
      <div class="formControls col-8">
        <input type="text" class="input-text" id="aurl" name="aurl" placeholder="请输入链接地址" value="{$res.ad_link}">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>广告图片：</label>
      <div class="formControls col-6"> <span class="btn-upload form-group">
        <input class="input-text upload-url" type="text" id="adImgUrl" name="adImgUrl" readonly style="width:250px" value="{$res.ad_url}" placeholder="请上传图像文件" />
        <a href="javascript:;" class="a-upload" onchange="uploadImage('myfile','ad','ad');"><input type="file" name="myfile" id="myfile" alt="上传文件">点击上传文件</a>	
        </span><br/><font color="#f00">*请按照尺寸上传图片</font>
      </div>
      <div class="formControls col-2">
        <img id="adImg" src="__UPLOAD__/{$res.ad_url|default='img/no_image.jpg'}" style="width:120px; height:60px; float: left">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>显示排序：</label>
      <div class="formControls col-8">
        <input type="text" class="input-text" placeholder="请输入排序，数值越小越靠前" id="asort" name="asort" value="{$res.ad_sort}">
      </div>
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-3">
        <input type="hidden" id="aid" name="aid" value="{$res.ad_id}">
        <button type="button" id="sub" name="sub" class="btn btn-primary radius" onClick="checkSubmit()"><i class='Hui-iconfont'>&#xe632;</i> 保存</button>
        <input class="btn btn-default radius" type="button" onClick="layer_close();" value="取消"/>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript">
//按回车件触发提交
document.onkeydown=function(event){
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode==13){ // enter 键
		checkSubmit();
	}
}; 
//提交数据
function checkSubmit()
{
	var aname = $.trim($('#aname').val());
	var type  = $.trim($('#type').val());
	var stime = $.trim($('#stime').val());
	var etime = $.trim($('#etime').val());
    var aurl  = $.trim($('#aurl').val());
	var imgurl= $.trim($('#adImgUrl').val());
	var asort = $.trim($('#asort').val());
	if(aname == ''){
		layer.msg('广告名称不能为空', {icon: 2});
		return false;
	}if(type == ''){
		layer.msg('广告位置未选择!', {icon: 2});
		return false;
	}if(stime == ''){
		layer.msg('开始时间不能为空!', {icon: 2});
		return false;
	}if(etime == ''){
		layer.msg('结束时间不能为空!', {icon: 2});
		return false;
	}if(aurl == ''){
		layer.msg('广告链接不能为空!', {icon: 2});
		return false;
	}if(imgurl == ''){
		layer.msg('广告图片未上传!', {icon: 2});
		return false;
	}if(asort == ''){
		layer.msg('显示排序不能为空!', {icon: 2});
		return false;
	}
	$.ajax({
		type : 'post',
		url : '__MODULE__/Ad/adAddEdit',
		data : $("#myform").serialize(),
		dataType : 'json',
		success : function(res){
			if(res.status == 1){
				layer.msg(res.msg,{icon:1,time:2000},function(){
					// 先获取窗口索引，才能关闭窗口  
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				});
				parent.call_back_fun('success');
			}else{
				layer.msg(res.msg, {icon: 2});
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			layer.alert('网络失败，请刷新页面后重试',{icon:2});
		}
	})
}
</script>
<!-- 图片上传 -->
<style type="text/css">
#file_upload{ float:right}
#file_upload-queue{ display:none}
</style>
<link href="__PUBLIC__/lib/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/lib/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript"> 
$(function() {
	$('#file_upload').uploadify({
        'swf'      : '__PUBLIC__/lib/uploadify/uploadify.swf',
        'uploader' : '__MODULE__/Uploader/setupFile?id=ad',
 		'buttonText' : '广告图片',
        'onUploadSuccess' : function(file, data, response) {
			$('#bimg').attr('src','__UPLOAD__/'+ data);
			$('#bimgurl').val(data);
        },
    });

});
</script>
<!-- 图片上传 -->
</body>
</html>